//
// Created by 123 on 2024/3/1.
//
#include <iostream>

using namespace std;

#define MaxSize 10

typedef struct {
    int data[MaxSize];
    int top;
} SqStack;

//初始化
void initStack(SqStack &s);

//判空栈
bool isEmpty(SqStack s);

//进栈
bool push(SqStack &s, int e);

//出栈
bool pop(SqStack &s, int &e);

//读取栈顶元素
bool getTop(SqStack &s, int &e);

void show(SqStack s);

int main() {
    SqStack s;
    initStack(s);
    cout << isEmpty(s) << endl;

    push(s, 1);
    push(s, 2);
    push(s, 3);
    push(s, 4);
    cout << isEmpty(s) << endl;
    int e = -1;
    pop(s, e);
    cout << e << endl;
    pop(s, e);
    cout << e << endl;
    getTop(s, e);
    cout << e << endl;
    getTop(s, e);
    cout << e << endl;


    show(s);


}

void initStack(SqStack &s) {
    s.top = -1;
}

bool isEmpty(SqStack s) {
    return s.top == -1;
}

bool push(SqStack &s, int e) {
    if (s.top == MaxSize - 1)
        return false;
    s.data[++s.top] = e;
    return true;
}

bool pop(SqStack &s, int &e) {
    if (s.top == -1)
        return false;
    e = s.data[s.top--];
    return true;
}

bool getTop(SqStack &s, int &e) {
    if (s.top == -1)
        return false;
    e = s.data[s.top];
    return true;
}

void show(SqStack s) {
    for (int i = 0; i < MaxSize; ++i) {
        cout << s.data[i] << "   ";
    }
    cout << endl;
}